package com.app.utils;

import android.graphics.Bitmap;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

import phone.qyg.com.qyg.R;


/**
 * 图片下载默认设置
 * 现在还没有定图片 所有图片都一图标作为默认图片
 *
 * @author lblbh
 */
public class OptionImageUtils {


    /**
     * 这个默认图片的比利时4:3
     * 全局默认拿这张图片 设置信息
     *
     * @return
     */
    public static DisplayImageOptions getDelfaultOption() {
        @SuppressWarnings("deprecation")
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showStubImage(R.drawable.defalut_load_32)
                .showImageForEmptyUri(R.drawable.defalut_32)
                .showImageOnFail(R.drawable.defalut_32)
                .resetViewBeforeLoading(true)
                .cacheOnDisc(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
		        .displayer(new FadeInBitmapDisplayer(200))//是否图片加载好后渐入的动画时间
//                .displayer(new RoundedBitmapDisplayer(20))//是否设置为圆角，弧度为多少
                .build();
        return options;
    }


    /**
     * 正方形张图片 设置信息
     *
     * @return
     */
    public static DisplayImageOptions getRectRatio43() {
        @SuppressWarnings("deprecation")
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showStubImage(R.drawable.defalut_load_43)
                .showImageForEmptyUri(R.drawable.defalut_43)
                .showImageOnFail(R.drawable.defalut_43)
                .resetViewBeforeLoading(true)
                .cacheOnDisc(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
//		.displayer(new_icon FadeInBitmapDisplayer(300))//是否图片加载好后渐入的动画时间
                .build();
        return options;
    }

    /**
     * 正方形张图片 设置信息
     *
     * @return
     */
    public static DisplayImageOptions getRectRatioAct() {
        @SuppressWarnings("deprecation")
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showStubImage(R.drawable.defalut_load_act)
                .showImageForEmptyUri(R.drawable.defalut_act)
                .showImageOnFail(R.drawable.defalut_act)
                .resetViewBeforeLoading(true)
                .cacheOnDisc(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
//		.displayer(new_icon FadeInBitmapDisplayer(300))//是否图片加载好后渐入的动画时间
                .build();
        return options;
    }

    /**
     * 轮图 设置信息
     *
     * @return
     */
    public static DisplayImageOptions getRoll() {
        @SuppressWarnings("deprecation")
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showStubImage(R.drawable.defalut_load_32)
                .showImageForEmptyUri(R.drawable.defalut_32)
                .showImageOnFail(R.drawable.defalut_32)
                .resetViewBeforeLoading(true)
                .cacheOnDisc(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
//		.displayer(new_icon FadeInBitmapDisplayer(300))//是否图片加载好后渐入的动画时间
                .build();
        return options;
    }



    public static DisplayImageOptions getPersonIcon() {
        @SuppressWarnings("deprecation")
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showStubImage(R.drawable.my_head)
                .showImageForEmptyUri(R.drawable.my_head)
                .showImageOnFail(R.drawable.my_head)
                .resetViewBeforeLoading(true)
                .cacheOnDisc(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .displayer(new FadeInBitmapDisplayer(200))
                .build();
        return options;
    }

    public static DisplayImageOptions getClassify() {
        @SuppressWarnings("deprecation")
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showStubImage(R.drawable.ic_launcher)
                .showImageForEmptyUri(R.drawable.ic_launcher)
                .showImageOnFail(R.drawable.ic_launcher)
                .resetViewBeforeLoading(true)
                .cacheOnDisc(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .displayer(new FadeInBitmapDisplayer(200))
                .build();
        return options;
    }

    public static DisplayImageOptions getCertificateDelfaultOption() {
        @SuppressWarnings("deprecation")
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showStubImage(R.drawable.ic_launcher)
                .showImageForEmptyUri(R.drawable.ic_launcher)
                .showImageOnFail(R.drawable.ic_launcher)
                .resetViewBeforeLoading(true)
                .cacheOnDisc(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .displayer(new FadeInBitmapDisplayer(200))
                .build();
        return options;
    }


    public static void setImage43(ImageView img,String url){
        if(img == null) return;
        ImageLoader.getInstance().displayImage(url,img,getRectRatio43());
    }
}
